import { Vec3 } from "cc";

/**
 * 数学工具类
 */
export default class MathUtil {

    /**从两个数之间返回一个随机数 */
    static randomNum(num1: number, num2: number): number {
        let random = Math.random() * (num2 - num1) >> 0;
        return num1 + random;
    }

    static rateBingo(rate: number) {
        return rate > Math.random()
    }

    static distance2D(v1: Vec3, v2: Vec3): number {
        return Math.sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y))
    }

    /**把一个数变为1，保留正负性 */
    static toOne(num: number): number {
        num = Math.sign(num);
        return num >= 0 ? 1 : -1;
    }
}